<!DOCTYPE html>
<html lang="en">
<head>
	<meta content="width=device-width,initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
	<meta name="apple-mobile-web-app-capable" content="no" />
	<meta charset="UTF-8">
	<title>用户登录</title>
	<!-- <link rel="stylesheet" type="text/css" href="../css/all.css"> -->
	<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/mui.min.js"></script>
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/css/mui.min.css" rel="stylesheet" />
	<link rel="stylesheet" type="text/css" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/css/app.css?v=">
	<link rel="stylesheet" type="text/css" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/sui/css/SUI.css">
	<link rel="stylesheet" type="text/css" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/sui/font/iconfont.css">
	<style type="text/css"></style>
</head>
<style type="text/css">
	.other a{color:#333;}
</style>
<body class="login">
	<form>
	<input type="tel" name="mobile" placeholder="手机号码">
	<input type="password" name="password" placeholder="登录密码">
	<span class="yzm suiDisn"><input type="tel" name="code" placeholder="短信验证码"><span class="get">获取验证码</span></span>
	</form>
	<button id="login">确认登录</button>
	<p id="type" data="0">手机直接登录/注册</p>
	<span class="butt fl" onclick="back()">关闭</span>
	<span class="butt fr" onclick="sign()">注册</span>
	<div class="other suiOp7">
		<dl>
			<dt><span>其他登录</span></dt>
			<dd class="wxlogin">
				<img src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/icon-wechat-a.png" alt="">
				<span>微信</span>
			</dd>
			<!-- <a href="/mobile/login_qq">
			<dd class="qqlogin">
				<img src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/icon-qq-a.png" alt="" onclick="qqlogin()">
				<span>QQ</span>
			</dd>
			</a> -->
			<!-- <dd>
				<img src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/alipay.png" alt="" onclick="alilogin()">
				<span>支付宝</span>
			</dd> -->
		</dl>
	</div>
</body>
<!-- <script src="https://api.map.baidu.com/api?v=3.0&ak=reS8936U13ZRG55lwohgtuubGqwNvsqh&s=1" type="text/javascript"></script> -->
<script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/sui/js/SUI.js"></script>
<script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/js/zepto.min.js"></script>
{{template "wechat/public/share.html" .}}
<script type="text/javascript" language="javascript">
	// var city = ''
	// {{if .currentcity}} 
	// console.log(1)
	// {{else}}
	// console.log(2)
 //    var geolocation = new BMap.Geolocation() 
 //    geolocation.getCurrentPosition(function(r){  
 //        if(this.getStatus() == BMAP_STATUS_SUCCESS){  
 //            var pt = new BMap.Point(r.point.lng,r.point.lat)  
 //            var geoc = new BMap.Geocoder()
 //            geoc.getLocation(pt, function(rs){
 //                var addComp = rs.addressComponents
 //                city = addComp.city
 //                console.log(city)
 //            });      
 //        }  
 //        else {  
 //          var myCity = new BMap.LocalCity()
 //          myCity.get(Ipmap)        
 //        }          
 //    },{enableHighAccuracy: true})
 //    function Ipmap(res) {
 //      city = res.name
 //      console.log(city)
 //    }
 //    {{end}}
	function isWeiXin() {
		var ua = window.navigator.userAgent.toLowerCase();
		if (ua.match(/MicroMessenger/i) == 'micromessenger') {
			return true;
		} else {
			return false;
		}
	}
	document.getElementsByClassName("wxlogin")[0].onclick=function(){
		window.location.href="/mobile/login_wechat"
	}
	// if(!isWeiXin()){
	// 	document.getElementsByClassName("wxlogin")[0].style.display="none"
	// 	document.getElementsByClassName("wxlogin")[0].onclick=null
	// 	// document.getElementsByClassName("qqlogin")[0].style.marginLeft = '29.4vw'
	// }
	function sign(){
		location.href="./sign.html"
	}
	function back(){
		history.back()
	}
	var yzm = 0;
	function back(){
		history.back()
	}
	// var value = "";
	// var date;
	$('span.get').click(function(event) {
		var mobile=$("input[name=mobile]").val()
		if ( mobile== "") {
			mui.toast("请输入手机号码~")
		}else if (!/^1[3456789]\d{9}$/.test(mobile)) {
			mui.toast("请输入正确的号码~")
		} else {
			if (yzm == 0) {
				var that=this
				that.disabled=true
				$.ajax({
					url:'/mobile/login/smssend',
					data:{mobile:mobile,type:0},
					success:function(res){
						if(res==1){
							// mui.toast("验证码获取成功~")
							$('.get').text('60秒后重新获取')		
							timeout()
							yzm = 1
						}else if(res==0){
							mui.toast("服务繁忙,请稍后再试~")
						}else if(res==2){
							mui.toast("该号码未注册,请先注册~")
						}else{
							mui.toast("服务繁忙,请稍后再试~")
						}
						that.disabled=false
					},
					error:function(){
						mui.toast("服务繁忙,请稍后再试~")
						that.disabled=false
					}
				})
			}else {
				mui.toast("请稍后再在获取~")
			}
		}
	});
	$('#login').click(function(){
		var type=$('#type').attr('data')
		var mobile=$("input[name=mobile]").val()
		if(!/^1[3456789]\d{9}$/.test(mobile)){
			mui.toast("请输入正确的号码~");
			return false;
		}
		if (type==1){
			if($("input[name=code]").val().length!=6){
				mui.toast("请输入验证码~");
				return false;
			}
		}else{
			if($("input[name=password]").val()==""){
				mui.toast("请输入密码~");
				return false;
			}
		}
		var that=this
		that.disabled=true
		var form=$('form').serialize()
		form+=`&style=`+type
		$.ajax({
			url:window.location.href,
			data:form,
			type:'post',
			success:function(res){
				if(res==1){
					if(document.referrer){
						if(document.referrer=="http://test.tongcaigou.com/mobile/login"&&document.referrer=="http://test.tongcaigou.com/mobile/sign"&&document.referrer=="http://test.tongcaigou.com/mobile/my/info"){
							window.location.href="/mobile/my"
						}else{
							window.location.href=document.referrer
						}
					}else{
						window.location.href="/mobile/my"
					}
				}else if(res==2){
					mui.toast("验证码错误!");
				}else if(res==3){
					mui.toast("该号码未注册!");
				}else if(res==0){
					mui.toast("密码错误!");
				}else{
					mui.toast("服务繁忙,请稍后再试~")
				}
				that.disabled=false
			},error:function(){
				mui.toast("服务繁忙,请稍后再试~")
				that.disabled=false
			}
		})
	})
	function timeout(){
		var time = 60;
		var tt = setInterval(function(){
			if (time == '0') {
				$('.get').text('重新获取验证码')
				clearInterval(tt)
				yzm = 0
			}else {
				time--
				$('.get').text(time+'秒后重新获取')
			}
		},1000)
	}

	// 切换登录方式
	var tab = document.querySelector("#type")
	tab.onclick = function(){
		if (this.attributes["data"].nodeValue == "0") {
			document.querySelector("input[name=password]").style.display = 'none'
			document.querySelector("span.yzm").className = 'yzm'
			this.attributes["data"].nodeValue = "1"
			this.innerText = "密码验证登录"
		}else{
			document.querySelector("input[name=password]").style.display = 'block'
			document.querySelector("span.yzm").className = 'yzm suiDisn'
			this.attributes["data"].nodeValue = "0"
			this.innerText = "手机直接登录/注册"
		}
	}
</script>
</html>